<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2019/7/20
 * Time: 20:08
 */

namespace app\home\controller;


use think\Controller;
use think\Db;

class Mobile extends Controller
{
    /**
     * 手机端微信小程序
     */
    public function index()
    {
        if (request()->isPost()) {
            $data = input('post.');
            $res = Db::name('nyd_control_dev')->where('id',$data['id'])->update(['is_open'=>$data['is_open']]);
            if ($res){
                return json([
                   'code' => 200,
                    'message' => 'success',
                    'data' => $res
                ]);
            }
            else{
                return json([
                    'code' => 400,
                    'message' => 'fail',
                    'data' => []
                ]);
            }

        } else {
            $re = Db::name('nyd_control_dev')->where('is_del', 1)->select();
            if ($re) {
                return json([
                    'code' => 200,
                    'message' => 'success',
                    'data' => $re
                ]);
            } else {

                return json([
                    'code' => 400,
                    'message' => '请求数据失败',
                    'data' => []
                ]);
            }


        }
    }

    /**
     * 检测是否开启手机端
     */
    public function init(){
        $start = Db::name("system")->field('mobile')->find();
        if ($start['mobile']=='open'){
            return json([
                'code' => 200,
                'message' => '手机端开启',
                'data' => $start
            ]);
        }
        else{
            return json([
                'code' => 400,
                'message' => '手机端已关闭',
                'data' => $start
            ]);
        }
    }
}